﻿@using CodeGenerator.Core
@using System.Text
@{
    BuildHCodeCreate model = Model;
    string permissionStr = string.Empty;
    string areaName = string.Empty;
    if(model.ViewAuthorization)
    {
        permissionStr = "[Permission]";
    }
    if(!string.IsNullOrEmpty(model.AreaName))
    {
        areaName = "."+model.AreaName;
    }
}
using HPK.Application.Busines;
using HPK.Application.Code;
using HPK.Application.Entity;
using HPK.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HPK.Application@(areaName).Controllers
{
    /// <summary>
    /// @(model.TableInfo.Comments)
    /// </summary>
    public class @(model.Name)Controller : AdminController
    {
        @(model.Name)Bll bll = new @(model.Name)Bll();

        #region 视图
        @permissionStr
        public ActionResult Index()
        {
            return View();
        }

        @permissionStr
        public ActionResult Form()
        {
            return View();
        }
        #endregion

        #region 获取数据（Json）
        /// <summary>
        /// @(model.TableInfo.Comments)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <returns>@(model.TableInfo.Comments)Json</returns>
        public ActionResult GetEntity(string keyValue)
        {
            return Content(bll.GetEntity(keyValue).ToJson());
        }

        /// <summary>
        /// 绑定表格
        /// </summary>
        /// <param name="pagination">分页条件</param>
        /// <param name="keywords"></param>
        /// <returns></returns>
        public ActionResult GetPageList(Pagination pagination,string keywords)
        {
            Stopwatch watch = CommonHelper.TimerStart();

            var list = bll.GetPageList(pagination,keywords);
            var jsonData = new
            {
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                costtime = CommonHelper.TimerEnd(watch),
                rows = list,
            };
            return Content(jsonData.ToJson());
        }

        #endregion

        #region 提交数据
        /// <summary>
        /// 添加/修改
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        @permissionStr
        public ActionResult Edit(@(model.Name)Entity entity, string keyValue)
        {
            int IsOk = bll.Edit(entity, keyValue);
            return IsOk > 0
                   ? Success("保存成功")
                   : Error("保存失败");
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        @permissionStr
        public ActionResult Delete(string keyValue)
        {
            int IsOk = bll.Delete(keyValue);

            return IsOk > 0
                ? Success("删除成功")
                : Error("删除失败");
        }
        #endregion
    }
}
